<?php

namespace app\common\model;
/**
 * [提现表]
 * @author [C。]
 * @return html
 */
class Draw extends Base
{
    protected $name = 'draw';

    /**
     * 获取提现列表
     * @param array $param
     */
    public function getDrawByCondition($map, $from = 0, $size = 5,$field='*') {
        $order = ['id' => 'desc'];
        return $this->field($field)->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();
    }
    /**
     * 搜索获取充值列表
     * @param array $param
     */
    public function getlist($map, $from = 0, $size = 5,$key='') {
        if ($key == 1){
            $join = [
                ['app_acts aa', 'aa.id = d.item_id'],
            ];
            $field = 'd.*,aa.title actname';
        }elseif($key == 2) {
            $join = [
                ['app_company ac', 'ac.id = d.comid'],
            ];
            $field = 'd.*,ac.comname';
        }elseif($key == 3) {
            $join = [
                ['app_manager am','am.id = d.manager_id'],
            ];
            $field = 'd.*,am.username,am.tel';
        }
        $order = ['d.id' => 'desc'];
        return $this->field($field)
            ->alias('d')
            ->join($join)
            ->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();
    }
    /**
     * 搜索获取体现列表总数
     * @param array $param
     */
    public function getCount($map,$key='') {
        if ($key == 1){
            $join = [
                ['app_acts aa', 'aa.id = d.item_id'],
            ];
            $field = 'd.*,aa.title actname';

        }elseif($key == 2) {
            $join = [
                ['app_company ac', 'ac.id = d.comid'],
            ];
            $field = 'd.*,ac.comname';
        }elseif($key == 3) {
            $join = [
                ['app_manager am','am.id = d.manager_id'],
            ];
            $field = 'd.*,am.username,am.tel';
        }
        return $this->field($field)
            ->alias('d')
            ->join($join)
            ->where($map)
            ->count();
    }
    /**
     * 获取提现列表总数
     * @param array $param
     */
    public function getDrawCount($map) {
        return $this->where($map)->count();
    }
    /**
     * 获取最大提现次数
     * @param array $param
     */
    public function getMaxnum($map,$field) {
        return $this->where($map)->max($field);
    }
}
